package com.school.generator.mapper;

import com.school.generator.bean.FiledBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @program: humble_boot
 * @description:
 * @author: sunpx
 * @create: 2022-04-26 21:25
 **/
@Mapper
public interface CodeGeneratorMapper {


    @Select("select table_name, table_comment from information_schema.tables where table_schema =#{database};")
    List<Map<String, String>> tableList(@Param("database") String database);


    @Select("select column_name                        field_name,\n" +
            "       if(COLUMN_KEY = 'PRI', 1, 0)       is_column_key,\n" +
            "       COLUMN_TYPE                        field_type,\n" +
            "       COLUMN_COMMENT                     notes,\n" +
            "       if(IS_NULLABLE = 'NO', 1, 0)       is_null,\n" +
            "       if(EXTRA = 'auto_increment', 1, 0) id_type\n" +
            "from information_schema.columns\n" +
            "where table_name = #{tableName} \n" +
            "  and table_schema = #{database}")
    List<FiledBean> getByTableFieldList(@Param("tableName") String tableName,@Param("database") String dataSource);


    @Select("select table_name, table_comment from information_schema.tables where table_schema =#{database} and table_name=#{tableName};")
    Map<String, String> tableInfo(String database, String tableName);
}
